import 'package:flutter/material.dart';

class GoodsDetailsModel {
  late List<SkuModel> skus;
  late  List<Goods> goods;

  GoodsDetailsModel({required this.skus, required this.goods});

  GoodsDetailsModel.fromJson(Map<String, dynamic> json) {
    if (json['skus'] != null) {
      skus = <SkuModel>[];
      json['skus'].forEach((v) {
        skus.add(SkuModel.fromJson(v));
      });
    }
    if (json['goods'] != null) {
      goods = <Goods>[];
      json['goods'].forEach((v) {
        goods.add(Goods.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (skus != null) {
      data['skus'] = skus.map((v) => v.toJson()).toList();
    }
    if (goods != null) {
      data['goods'] = goods.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Goods {
  late String name;
  late List<String> items;

  Goods({required this.name, required this.items});

  Goods.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    items = json['items'].cast<String>();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['name'] = name;
    data['items'] = items;
    return data;
  }
}

class SkuModel {
  late Color color;
  late int price;
  late int count;
  late String sku;

  SkuModel({required this.color, required this.price, required this.count, required this.sku});

  SkuModel.fromJson(Map<String, dynamic> json) {
    color = json['color'];
    price = json['price'];
    count = json['count'];
    sku = json['sku'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['color'] = color;
    data['price'] = price;
    data['count'] = count;
    data['sku'] = sku;
    return data;
  }
}
